<template>

  <div class="app-container">
    <el-select
      v-model="storageselect"
      class="selectInput"
      collapse-tags-tooltip:true
      collapse-tags:true
      @change="handleChange"
      placeholder="请选择一级仓库"
    >
      <el-option
        v-for="item in storageListArr"
        :key="item.id"
        :label="item.storageName"
        :value="item.id"
      />
    </el-select>
    <el-select
      v-model="roomselect"
      class="selectInput"
      collapse-tags-tooltip:true
      @change="handleRoomChange"
      placeholder="请选择二级仓库"
    >
      <el-option
        v-for="item in roomListArr"
        :key="item.id"
        :label="item.roomName"
        :value="item.id"
      />
    </el-select>
    <el-table v-loading.body="listLoading" :data="list" border fit highlight-current-row style="width: 100%">

      <el-table-column width="120px" align="center" label="uid">
        <template slot-scope="scope">
          <span>{{ scope.row.uid }}</span>
        </template>
      </el-table-column>
      <el-table-column width="120px" align="center" label="用户名称">
        <template slot-scope="scope">
          <span>{{ scope.row.username }}</span>
        </template>
      </el-table-column>
      <el-table-column width="120px" align="center" label="一级仓库名称">
        <template slot-scope="scope">
          <span>{{ scope.row.roomName }}</span>
        </template>
      </el-table-column>
      <el-table-column width="120px" align="center" label="二级仓库名称">
        <template slot-scope="scope">
          <span>{{ scope.row.storageName }}</span>
        </template>
      </el-table-column>


      <el-table-column width="120px" align="center" label="国际区号">
        <template slot-scope="scope">
          <span>{{ scope.row.userName }}</span>
        </template>
      </el-table-column>

      <el-table-column width="120px" align="center" label="手机号">
        <template slot-scope="scope">
          <span>{{ scope.row.mobile }}</span>
        </template>
      </el-table-column>

      <el-table-column width="120px" align="center" label="角色">
        <template slot-scope="scope">
          <span>{{ scope.row.position | getPositionName }}</span>
        </template>
      </el-table-column>


      <el-table-column align="center" label="操作" width="120">
        <template slot-scope="scope">
          <router-link :to="'/usermenu/storageusermain/detail?id='+scope.row.uid">
            <el-button type="primary" size="small" icon="el-icon-edit">详情</el-button>
          </router-link>
        </template>
      </el-table-column>
    </el-table>

    <div class="pagination-container">
      <el-pagination
        :current-page="listQuery.page"
        :page-sizes="[10,20,30, 50]"
        :page-size="listQuery.limit"
        :total="total"
        background
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"/>
    </div>

  </div>
</template>

<script>
import { fetchList } from '@/api/storageuser'
import {storageList} from  '@/api/storage'
import { roomList } from  '@/api/room'
export default {
  name: 'StorageUserList',
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'info',
        deleted: 'danger'
      }
      return statusMap[status]
    },
    getPositionName(position) {
      if (position === 1) {
        return '管理员';
      }else if (position === 2) {
        return '技术员';
      }else if (position === 3) {
        return '租户'
      }
    }

  },

  data() {
    return {
      storageselect:'',
      roomselect:'',
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 10
      },
      searchShow:1,
      options :[
        {
          value: '1',
          label: '一级仓库',
        },
        {
          value: '2',
          label: '二级仓库',
        },

      ],
      roomListArr:[],
      storageListArr: [] ,

    }
  },
  created() {
    storageList({ "uissssd" : 1269 , "page": 1, "limit" : 5000 , "status" : 0 } ).then(response => {
      this.storageListArr = response.data.data
    })
    this.getList()
  },
  methods: {
    handleRoomChange(val){
      this.roomselect  = val
      this.getList()
    },
    handleChange(val){
      this.storageselect = val
      this.getRoomList()
    },
    getRoomList(){
      this.fetchRoomData(this.storageselect)
    },
    fetchRoomData(sid){
      roomList({ page: 1, limit: 1000, sid:sid }).then(response => {
        this.roomListArr = response.data.data

      })
    },
    getList() {
      this.listLoading = true
      this.listQuery.rid = this.roomselect
      this.listQuery.sid = this.storageselect
      fetchList(this.listQuery).then(response => {
        this.list = response.data.data
        console.log(this.list)
        this.total = 10
        this.listLoading = false
      })
    },
    handleSizeChange(val) {
      this.listQuery.limit = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.listQuery.page = val
      this.getList()
    }
  }
}
</script>

<style scoped>
.edit-input {
  padding-right: 100px;
}
.cancel-btn {
  position: absolute;
  right: 15px;
  top: 10px;
}
</style>
